/*
 *   对后端数据的Api调用
 *
 */
import request from './request.js'
import store from '@/store'
export function login(username, password) {
  return new Promise((resolve, reject)=>{
    request.post('user/login', {username: username, password: password})
      .then(data=> {
        resolve(data.data)
      }).catch(error=>{
        console.log(`api.login error(${error.code}): ${error.messsage}`)
        reject(error)
      })
  })
}
export function logout() {
  return new Promise((resolve, reject)=>{
    request.post('user/logout')
      .then(data=> resolve(data.data))
      .catch(error=>{
        console.log(`api.logout error(${error.code}): ${error.messsage}`)
        reject(error)
      })
  })
}
export function getUserInfo() {
  return new Promise((resolve, reject)=>{
    request.get('user/info')
      .then(data=> {resolve(data.data); })
      .catch(error=>{
        console.log(`api.getUserInfo error(${error.code}): ${error.messsage}`)
        reject(error)
      })
  })
}
export function getTableList() {
  return new Promise((resolve, reject)=>{
    request.get('table/list')
      .then(data=> resolve(data.data))
      .catch(error=>{
        console.log(`api.getTableList error(${error.code}): ${error.messsage}`)
        reject(error)
      })
  })
}
export function getTransactions() {
  return new Promise((resolve, reject)=>{
    request.get('transaction/list')
      .then(data=> resolve(data.data))
      .catch(error=>{
        console.log(`api.getTransactions error(${error.code}): ${error.messsage}`)
        reject(error)
      })
  })
}
